package com.loginlib.table.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.loginlib.R;
import com.wanhe.base.model.disgn.TableBillModel;

import java.util.ArrayList;

/**
 * Created by XieZaiWei on 2017/4/26.
 * 已下单某分类菜品下子列表的Adapter
 */

public class TableBillChildAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private ArrayList<TableBillModel> mArrTableBill;


    public TableBillChildAdapter(Context context, ArrayList<TableBillModel> arrTableBill) {
        mInflater = LayoutInflater.from(context);
        mArrTableBill = arrTableBill;
    }

    @Override
    public int getCount() {
        return mArrTableBill.size();
    }

    @Override
    public TableBillModel getItem(int position) {
        return mArrTableBill.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.table_bill_child_item, null);
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.tv_price = (TextView) convertView.findViewById(R.id.tv_price);
            viewHolder.tv_count = (TextView) convertView.findViewById(R.id.tv_count);
            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        TableBillModel tableBill = mArrTableBill.get(position);

        viewHolder.tv_name.setText(tableBill.getVch_dishname());

        viewHolder.tv_price.setText("￥" + tableBill.getNum_price1() + "/" + tableBill.getVch_unitname());
        viewHolder.tv_count.setText("x" + tableBill.getNum_num());


        return convertView;
    }

    private static class ViewHolder {
        public TextView tv_name;
        public TextView tv_price;
        public TextView tv_count;
    }
}
